package test;

import javax.swing.*;
import java.awt.*;

public class JFrameDemo02 {
    public static void main(String[] args) {
        new MyJFrame2().init();
    }

}

class MyJFrame2 extends JFrame{
    public void  init(){
        this.setBounds(100,100,200,200);
        this.setVisible(true);
        JLabel label = new JLabel("欢迎学习Java");
        this.add(label);
        //让文本标签居中  设置水平对齐
        label.setHorizontalAlignment(SwingConstants.CENTER);
        //获得一个容器
        Container content = this.getContentPane();
        content.setBackground(Color.cyan);
    }
}
